﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraEditors;
using DevExpress.XtraBars.Helpers;
using DevExpress.Utils;
using System.Configuration;
using QLKHACHHANG.DanhMucForm;


namespace QLKHACHHANG
{
    public partial class frmMainForm : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public Dictionary<Type, Form> FormList = new Dictionary<Type, Form>(); // luu danh sach form
        public frmMainForm()
        {
            InitializeComponent();
            InitSkinGallery();         
        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {             
            ShowForm<frmHome>(true);
            frmHome home = FormList[typeof(frmHome)] as frmHome;
            TabManager.Pages[home].ShowCloseButton = DefaultBoolean.False;                             

        }
       
        private void tabMain_CloseButtonClick(object sender, EventArgs e)
        {
            //tabMain.SelectedTabPage.Hide();
            //MessageBox.Show(tabMain.SelectedTabPage.Text);
            //tabMain.SelectedTabPage.PageVisible = false;
        }

        private void btKH_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));            
            ShowForm<frmCustomer>(true);            
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void iExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Close();
         
        }

        private void frmMainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            
            if (DialogResult.Yes == MessageBox.Show(
          "Bạn có muốn thoát khoải chương trình ?",
          "Thoát khoải chương trình?",
           MessageBoxButtons.YesNo,
           MessageBoxIcon.Question,
           MessageBoxDefaultButton.Button2))
            {
                // thoat khoi cac tai nguyen
                Application.ExitThread();
            }
            else
                e.Cancel = true;
        }
        
        // show form len mainform
        public void ShowForm<T>(bool closeOpentabs = true) where T : Form,new()
        {
            Form instance;
            FormList.TryGetValue(typeof(T), out instance);
            if (instance == null || instance.IsDisposed)
            {                
                instance = new T();
                FormList[typeof(T)] = instance;
                instance.MdiParent = this;
                instance.Show();
            }
            else
            {
                instance.Activate();
            }
        }

        private void btLoaiKH_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<frmDebt>(true); 
        }

        private void btLoaikh_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));            
            ShowForm<frmLoaiKH>(true);
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void btDanhxung_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));
            ShowForm<frmDanhXung>(true);
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }
       
        private void btNhancungcap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));
            ShowForm<frmNhaCungCap>(true);
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void btNhomsanpham_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));
            ShowForm<frmNhomSanPham>(true);
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void bbtNhanvien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));
            ShowForm<frmStaff>(true);
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void bbtBophan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));
            ShowForm<frmBoPhan>(true);
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
       
        }     

        private void bbtDoimatkhau_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmChangePass frm = new frmChangePass();
            frm.ShowDialog();
        }

        private void bbtNhom_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));
            ShowForm<frmNhom>(true);
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }
      

    }
}